import matplotlib.pyplot as plt
import numpy as np
from scipy import signal


def u(t):
    return np.where(t >= 0, 1, 0)


def u2(t):
    return np.where(t >= -1, 2, 0)


def u3(t):
    return np.where(t <= -1, 1, 0)


t_min = -2
t_max = 10
T = 0.01
t = np.arange(t_min, t_max, T)
t_y = np.arange(t_min * 2, t_max * 2 - T, T)

x = u3(t) + u2(t)
h = np.exp(-(t - 1)) * u(t - 1)

y = signal.convolve(x, h * T)

plt.subplot(311)
plt.plot(t, x)

plt.xlabel('n')
plt.ylabel('x[n]')

plt.subplot(312)
plt.plot(t, h)
plt.xlabel('n')
plt.ylabel('h[n]')


plt.subplot(313)
plt.plot(t_y, y)
plt.xlabel('n')
plt.ylabel('y[n]')

plt.show()
